package com.ssm.opa.common.base.log;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Date;

/**
 * <p/>
 * Copyright: Copyright (c) 2016/12/5
 * <p/>
 * Company: 途牛科技有限公司华东分公司
 * <p/>
 *
 * @author wanghongqi@tuniu.com
 * @version 1.0.0
 * @project gtb-parent
 */
public class BusinessLogTemplate {
	private static final long serialVersionUID = 1L;
	private static final ObjectMapper JParse = new ObjectMapper();

	//日志级别
	private String level = "info";

	//系统码
	private String sysCode = "OPA";

	// 模块码
	private String module = "";

	//方法名
	private String action = "";

	// 自定义关键字
	private String key = "";

	// 日志记录系统时间，精确到毫秒，格式为：yyyy-MM-dd HH:mm:ss.SSS
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
	private Date time = new Date();

	// 业务操作时长，精确到毫秒（业务有正常的开始时间和结束时间，才计算）
	private Long duration = 0L;

	// 是否成功，1：成功；0：失败
	private Integer status = 1;

	// 异常码，如果业务操作或者指令操作失败，输出失败code
	private int errCode = 0;

	// 备注说明
	private String msg = "";

	public BusinessLogTemplate(String module, String action, String key, Long duration, Integer status, int errCode, String msg) {
		this.module = module;
		this.action = action;
		this.key = key;
		this.duration = duration;
		this.status = status;
		this.errCode = errCode;
		this.msg = msg;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getSysCode() {
		return sysCode;
	}

	public void setSysCode(String sysCode) {
		this.sysCode = sysCode;
	}

	public String getModule() {
		return module;
	}

	public void setModule(String module) {
		this.module = module;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public Long getDuration() {
		return duration;
	}

	public void setDuration(Long duration) {
		this.duration = duration;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public int getErrCode() {
		return errCode;
	}

	public void setErrCode(int errCode) {
		this.errCode = errCode;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getLevel() {
		return level;
	}

	public void setLevel(String level) {
		this.level = level;
	}

	@Override
	public String toString() {
		try {
			return JParse.writeValueAsString(this);
		} catch (JsonProcessingException e) {
			return null;
		}
	}
}
